package com.rico.deploy.service.impl;

import com.github.pagehelper.PageHelper;
import com.rico.deploy.entity.Campus;
import com.rico.deploy.entity.College;
import com.rico.deploy.mapper.CollegeMapper;
import com.rico.deploy.service.CollegeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @author 夏智力
 * @FileName CollegeImpl
 * @date 2021/4/29 21:53
 * @Software: IntelliJ IDEA
 */
@Service
public class CollegeServiceImpl implements  CollegeService {

    @Autowired
    private CollegeMapper collegeMapper;

    @Override
    public List<College> selectAll() {
        return collegeMapper.selectAll();
    }

    @Override
    public List<College> selectAll(Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        return collegeMapper.selectAll();
    }

    @Override
    public String selectCollegeCodeByCollegeName(String collegeName) {
        Example example = new Example(College.class);
        example.createCriteria().andEqualTo("collegeName",collegeName);
        return collegeMapper.selectOneByExample(example).getCollegeCode();
    }


    @Override
    public College selectByCampusName(String campus_name) {
        Example example = new Example(Campus.class);
        example.createCriteria().andEqualTo("campusName",campus_name);
        return collegeMapper.selectOneByExample(example);
    }

    @Override
    //根据id查询学院
    public College selectById(Integer id){
        return collegeMapper.selectByPrimaryKey(id);
    }

    //添加一个学院
    @Override
    public int insertCollege(College college){
        return collegeMapper.insert(college);
    }

    //删除一个学院
    @Override
    public int deleteCollegeById(Integer id) {
        return collegeMapper.deleteByPrimaryKey(id);
    }

    //更新一个学院
    @Override
    public int updateCollege(College college) {
        return collegeMapper.updateByPrimaryKeySelective(college);
    }
}
